﻿#define  _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>

int* SingleTwo(int* SingleTwo, int SingleTwoSize)
{
    int i = 0;
    int num = 0, num1 = 0, num2 = 0;
    int p = 0;
    for (i = 0; i < SingleTwoSize; i++)
    {
        num ^= SingleTwo[i];//找出两个单生数的异或数
    }
    for (i = 0; i < 32; i++)
    {
        if (num & (1 << i))
        {
            p = i;//找出该数二进制位第一个为 1 的位数
            break;
        }
    }
    while (SingleTwoSize--)//分类，根据该位的二进制位是否为1进行分类，分别异或
    {
        if (SingleTwo[SingleTwoSize] & (1 << p))
        {
            num1 ^= SingleTwo[SingleTwoSize];//
        }
        else
        {
            num2 ^= SingleTwo[SingleTwoSize];
        }
    }
    int* ret = (int*)malloc(2 * sizeof(int));
    ret[0] = num1;
    ret[1] = num2;
    return ret;;
}

int main()
{
    int arr[] = { 1, 2, 4, 1, 4, 3, 12, 3 };
    int* arrret;
    int sz = sizeof(arr) / sizeof(arr[0]);
    arrret = SingleTwo(arr, sz);
    for (int i = 0; i < 2; i++)
    {
        printf("%d ",arrret[i]);
    }
	return 0;
}

